package ExceptionDemo1;

import java.util.InputMismatchException;
import java.util.Scanner;

public class ExceptionDemo4_me {
    public static void main(String[] args) {
        System.out.println("开始测试");
        while (true) {
            try{
                test();
                System.out.println("测试成功");
                break;
            }
            catch(InputMismatchException e){
                System.out.println("输入年龄有误，请重新输入");
            }
            catch(Ageoutthrow e){
                System.out.println(e.getMessage());
            }
        }
    }
    public static void test()throws Ageoutthrow {
        System.out.println("请输入年龄：");
        Scanner sc = new Scanner(System.in);
        int age;
        try {
            age = sc.nextInt();
            System.out.println("输入年龄成功");
        } catch (InputMismatchException e) {
            throw e;
        }

        if (age < 1 || age > 100) {
            throw new Ageoutthrow("年龄超出范围");
        }
    }
}
